#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 114;
int t;
int a[N];        
int n;
int ans;
int Sum[N];
void dfs(int x, int last0, int last1, int sum){
    if(x == n + 1){
        ans = max(ans, sum);
        return ;
    }
    if(sum + Sum[n] - Sum[x - 1] <= ans){
        return ;
    }
    dfs(x + 1, x, last1, sum + (a[x] == a[last0]) * a[x]);
    dfs(x + 1, last0, x, sum + (a[x] == a[last1]) * a[x]);
}
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    for(int i = 1;i <= t; i++){
        ans = 0;
        cin >> n;
        for(int i = 1;i <= n; i++){
            cin >> a[i];
            Sum[i] = Sum[i - 1] + a[i];
        }
        dfs(1, 0, 0, 0);
        cout << ans << endl;
    }
    return 0;
}